﻿using System.Windows;
using AuchanScan.ViewModels;
using Microsoft.Phone.Controls;

namespace AuchanScan.Views
{
    public partial class MaVoiturePage : PhoneApplicationPage
    {
        public MaVoiturePage()
        {
            InitializeComponent();

            DataContext = ViewModelLocator.MaVoitureViewModelStatic;

            GeoLocMe();
        }

        private void GeoLocMe()
        {
            var geo = new GeoWatcher();

            ViewModelLocator.GeoViewModelStatic.SetLoading(true);

            geo.CoordinateChanged += (senderr, er) => {
                Deployment.Current.Dispatcher.BeginInvoke(() => { MyMap.Center = er.Position.Location; });
                ViewModelLocator.GeoViewModelStatic.ComputeCoordinate(er.Position.Location);
            };

            geo.LaunchGPS();
        }

        private void SavePosition_Click(object sender, RoutedEventArgs e)
        {
            (this.DataContext as MaVoitureViewModel).Save();
        }
    }
}